//134-加油站
class Solution {
    public int canCompleteCircuit(int[] gas, int[] cost) {
        int n=gas.length;
        int index=0;
        int Gas=0;
        int Cos=0;
        int sum=0;
        for(int i=0;i<n;i++){
            Gas+=gas[i];
            Cos+=cost[i];
            sum+=gas[i]-cost[i];
            if(sum<0){
                index=i+1;
                sum=0;
            }
        }
        if(Gas<Cos){
            return -1;
        }
        return index;

    }
}